<div ng-controller="userInfoController">
    <!-- begin breadcrumb -->
    <ol class="breadcrumb pull-right">
        <li><a ui-sref="app.home">汇票线</a></li>
        <li><a ui-sref="app.setting">系统设置</a></li>
        <li class="active">用户管理</li>
    </ol>
    <!-- end breadcrumb -->
    <!-- begin page-header -->
    <h1 class="page-header"><i class="fa fa-lg text-success fa-cog"></i> 用户管理</h1>
    <!-- end page-header -->
    
    <!-- begin row -->
    <div class="row">
        <!-- begin col-12 -->
        <div class="col-md-12">
            <!-- begin panel -->
            <div class="panel panel-inverse">
                <div class="panel-heading">
                    <div class="panel-heading-btn">
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-success" data-click="panel-reload"><i class="fa fa-repeat"></i></a>
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-warning" data-click="panel-collapse"><i class="fa fa-minus"></i></a>
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                    </div>
                    <h4 class="panel-title">用户管理</h4>
                </div>
                <div class="panel-body">
                    <div class="form-inline filter-option">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="pull-right">
                                    <select ng-model="filter.isValid" class="form-control input-sm">
                                        <option value="">状态...</option>
                                        <option value="1">有效</option>
                                        <option value="0">无效</option>
                                    </select>
                                    <input type="text" ng-model="filter.keyword" class="form-control input-sm" placeholder="关键词" />
                                    <button class="btn btn-sm btn-info" ng-click="reflash()"><i class="fa fa-search"></i> 筛选</button>
                                    <button class="btn btn-sm btn-success" ng-click="edit()"><i class="fa fa-plus-circle"></i> 新增</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table id="data-table" ng-table="tableParams" template-pagination="template/pagination.html" class="table table-striped table-bordered table-hover table-condensed">
                        <tr ng-repeat="item in $data">
                            <td data-title="'序号'" width="10%" class="text-center">{{ first + $index }}</td>
                            <td data-title="'用户姓名'" sortable="'username'" class="text-center">{{ item.username }}</td>
                            <td data-title="'有效'" sortable="'is_valid'" class="text-center"><i ng-show="item.is_valid" class="fa fa-lg fa-check text-success"></i><i ng-show ="!item.is_valid" class="fa fa-lg fa-times text-danger"></i></td>
                            <td data-title="'角色'" class="text-center">{{ item.role_name }}</td>
                            <td data-title="'最后登录时间'" sortable="'last_signin_time'" class="text-center">{{ item.last_signin_time | date: 'yyyy-MM-dd HH:mm:ss' }}</td>
                            <td data-title="'描述'" sortable="'description'" class="text-left">{{ item.description }}</td>
                            <td class="text-center width-100 text-nowrap">
                                <button class="btn btn-success btn-xs" ng-click="edit(item)"><i class="fa fa-edit"></i> 编辑</button>
                                <button class="btn btn-success btn-xs"  ng-click="remove(item)" ng-if="item.is_valid"><i class="fa fa-trash-o"></i> 删除</button>
                            </td>
                        </tr>
                    </table>
                </div>
                <!-- #modal-dialog -->
                <div class="modal fade" id="modal-edit">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <ng-form name="editForm" novalidate>
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h4 class="modal-title"><i class="fa fa-lg fa-edit text-success"></i> 用户信息</h4>
                                </div>
                                <div class="modal-body">
                                    <div class="form-horizontal form-inline">
                                        <div class="form-group" ng-class="{ 'has-error': editForm.username.$invalid && !editForm.username.$pristine }">
                                            <label class="col-md-4 control-label"><font color="red">*</font> 用户姓名：</label>
                                            <div class="col-md-8">
                                                <input type="text" name="name" ng-model="model.username" class="form-control" required />
                                            </div>
                                        </div>
                                        <div class="form-group" ng-class="{ 'has-error': editForm.password.$invalid && editForm.password.$dirty }">
                                            <label class="col-md-4 control-label"><font color="red">*</font> 用户密码：</label>
                                            <div class="col-md-8">
                                                <input type="password" name="password" ng-model="model.password" class="form-control" required />
                                            </div>
                                        </div>
                                        <div class="form-group" ng-class="{ 'has-error': editForm.role_id.$invalid && editForm.role_id.$dirty }">
                                            <label class="col-md-4 control-label"><font color="red">*</font> 角色：</label>
                                            <div class="col-md-8">
                                                <select name="role_id" ng-model="model.role_id" ng-options="item.id as item.role_name for item in roles" class="form-control" required></select>
                                            </div>
                                        </div>
                                        <div class="form-group" ng-class="{ 'has-error': editForm.description.$invalid && editForm.description.$dirty }">
                                            <label class="col-md-4 control-label"><font color="red">*</font> 描述：</label>
                                            <div class="col-md-8">
                                                <input type="text" name="description" ng-model="model.description" class="form-control" required />
                                            </div>
                                        </div>
                                        
                                        <div class="form-group" ng-show="model.id != null">
                                            <label class="col-md-4 control-label">有效：</label>
                                            <div class="col-md-8">
                                                <label class="checkbox-inline">
                                                    <input name="is_valid" type="checkbox" ng-model="model.isValid">
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                        </div>
                                <div class="modal-footer">
                                    <button type="submit" class="btn btn-sm btn-success" ng-click="save()" ng-disabled="editForm.$invalid"><i class="fa fa-save"></i> 保存</button>
                                    <button type="submit" class="btn btn-sm btn-success" ng-click="resetPassword()" ng-show="model.id != null"><i class="fa fa-save"></i> 重置密码</button>
                                    <button type="button" class="btn btn-sm btn-white" data-dismiss="modal"><i class="fa fa-share-square-o"></i> 关闭</button>
                                </div>
                            </ng-form>
                        </div>
                    </div>
                </div>
                <!-- #modal-dialog -->
                <div class="modal fade" id="modal-roles">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title"><i class="fa fa-lg fa-edit text-success"></i> {{ model.username }}</h4>
                            </div>
                            <div class="modal-body">
                                <div class="table-responsive">
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>角色</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr ng-repeat="item in roles">
                                                <td>{{ $index + 1 }}</td>
                                                <td>{{ item.role_name }}</td>
                                                <td><button class="btn btn-success btn-xs" ng-click="removeRole(item)"><i class="fa fa-trash-o"></i> 删除</button></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-sm btn-success" ng-click="selectRole(model.id)"><i class="fa fa-plus-circle"></i> 添加</button>
                                <button class="btn btn-sm btn-white" data-dismiss="modal"><i class="fa fa-share-square-o"></i> 关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- end panel -->
        </div>
        <!-- end col-12 -->
    </div>
    <!-- end row -->
</div>